package com.baidu.disk.utils;

import com.alibaba.fastjson.JSON;
import com.baidu.disk.bean.ElementBean;
import com.baidu.disk.bean.MemoryInfoBean;
import com.baidu.disk.bean.RequestBean;
import com.baidu.disk.bean.ShareInfoBean;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpStatus;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Connection;
import org.jsoup.Jsoup;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;

/**
 * Created by CJ on 2018-02-28.
 */
public class DiskUtils {
    /**
     *
     *
     * @param parentPath  文件夹路径
     * @param size 需要文件夹及文件的显示个数,null表示默认100个
     * @return
     * @throws IOException
     */
    //获取列表中的json数据
    public static String getJson(RequestBean requestBean,String parentPath,Integer size) throws IOException {
        //获取请求连接
        Connection con =    JsoupUtils.getConnection(requestBean);
        if (size != null) {
            con.data("num", size+"");
        }else {
            con.data("num", "100");
        }
        if (!StringUtils.isEmpty(parentPath)) {
            con.data("dir", parentPath);
        }else {
            con.data("dir","/");
        }

        //解析请求结果
            Connection.Response execute = con.execute();
        //返回内容json
        return execute.body();
    }


    //将列表json转为集合
    public static List elementsListJsonToObj(String content) throws IOException {
        JSONObject json = new JSONObject(content);

        ElementBean elementBean = new ElementBean();
        JSONArray list = null;
        if (!json.isNull("list")) {
            list = json.getJSONArray("list");
        }else {
            System.out.println("json中未获取到list元素！！！");
            return  null;
        }

        List<ElementBean> elementBeans = new ArrayList<>();

        ElementBean b = null;
        for (int i = 0; i < list.length(); i++) {
            JSONObject jsonObject = list.getJSONObject(i);
            if (jsonObject == null) break;

            b = new ElementBean();
            //将json转化为bean对象
            b.setCategory(jsonObject.getInt("category") + "");
            b.setFsId(jsonObject.getBigInteger("fs_id") + "");
            if (jsonObject.isNull("dir_empty"))
                b.setDirEmpty("0");
            else
                b.setDirEmpty(jsonObject.getInt("dir_empty") + "");
            b.setOperId(jsonObject.getBigInteger("oper_id") + "");
            b.setSize(jsonObject.getBigInteger("size") + "");
            b.setIsDir(jsonObject.getInt("isdir") + "");
            String path = jsonObject.getString("path");
            if (StringUtils.isNotEmpty(jsonObject.getString("path")))
                b.setPath(jsonObject.getString("path"));
            if (StringUtils.isNotEmpty(jsonObject.getString("server_filename")))
                b.setServerFilename(jsonObject.getString("server_filename"));
            b.setLocalCtime(new Date(jsonObject.getInt("local_ctime")));

            if (!jsonObject.isNull("md5"))
                b.setMd5(jsonObject.getString("md5"));

            elementBeans.add(b);

        }
        return  elementBeans;
    }

    //新建文件夹(完整路径名称)
    //e.g  级联新建是只返回最深层的文件夹
    public static ElementBean createFolder(RequestBean requestBean,String path)  {

        ElementBean elementBean = null;
        try {
            Connection connect = JsoupUtils.getConnection(requestBean)
                    .method(Connection.Method.POST)
                    .data("isdir", "1");
            String body = connect.execute().body();
            JSONObject jsonObject = new JSONObject(body);
            if (!jsonObject.isNull("errno") && jsonObject.getInt("errno") == 0) {
                elementBean = new ElementBean();
                elementBean.setFsId(jsonObject.getBigInteger("fs_id")+"");
                elementBean.setLocalCtime(new Date(jsonObject.getInt("ctime")));
                elementBean.setIsDir(jsonObject.getInt("isdir")+"");
                elementBean.setPath(jsonObject.getString("path"));
            }else {
                System.out.println("文件夹新建失败！");
                return  null;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return elementBean;
    }

    //获取当前磁盘状态
    public static MemoryInfoBean getMemoryInfo(RequestBean requestBean) throws IOException {
        Connection connection = JsoupUtils.getConnection(requestBean);
        String content = connection.execute().body();
        JSONObject jsonObject = new JSONObject(content);

        MemoryInfoBean memoryInfoBean =new MemoryInfoBean();
        memoryInfoBean.setTotal(jsonObject.getBigInteger("total")+"");
        memoryInfoBean.setExpire(jsonObject.getBoolean("expire"));
        memoryInfoBean.setFree(jsonObject.getBigInteger("free")+"");
        memoryInfoBean.setUsed(jsonObject.getBigInteger("used")+"");
        return memoryInfoBean;
    }

    //文件分享
    public static ShareInfoBean getShareInfoBean(RequestBean requestBean){
        ShareInfoBean shareInfoBean = null;
        try {
            Connection connection = JsoupUtils.getConnection(requestBean).method(Connection.Method.POST);
            String body = connection.execute().body();
            shareInfoBean = com.alibaba.fastjson.JSONObject.toJavaObject((JSON) JSON.parse(body), ShareInfoBean.class);
        } catch (IOException e) {
            System.out.println("文件分享报错！");
            e.printStackTrace();
        }
        return shareInfoBean;
    }

    private static String  uploadFile(RequestBean requestBean){
        //获取md5
        Connection connection = JsoupUtils.getConnection(requestBean);


        //options请求
        return null;
    }

    public static void main(String[] args) throws Exception {
       /* //列表
        String url = "https://pan.baidu.com/api/list?order=name&desc=0&showempty=0&web=1&page=1&t=0.3676122640604751&channel=chunlei&web=1&app_id=250528&bdstoken=a107e755769b100902519bb9ae266cee&logid=MTUxOTcxOTYxMjE3ODAuNDIwMTc1NDY1NTY1NzI5NQ==&clienttype=0";
        String cookie = "PANWEB=1



            ; bdshare_firstime=1496644750149; FP_UID=4a1833ca6f29714baf079a9790f28c7c; secu=1; PSTM=1497491654; BIDUPSID=CBEEA88423F134632B3067752AFC4183; BAIDUID=8E46A4EB4758D69DABBC6092ECD25484:FG=1; __cfduid=dbd5170cf36256a51d3d49ecaf23d38251500350738; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; BDCLND=EogXDLjK02advvE%2FvQiEYz1TIZ%2BNVDYlnK63XXLaI1Y%3D; SCRC=d47c39e1d7eaee07396777c74af230e9; BDUSS=XlOT29BM1ZUc2FxWDdUWC12NGV4dHo5MGx1Q3l3a2pKMX5mOGZib2U4RWRFcnBhQVFBQUFBJCQAAAAAAAAAAAEAAACu-7lRbmV2ZXJzdG9wMTEyNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB2FklodhZJae; STOKEN=167a17a10746c1b7f00e9bcb64d6f587fdd175e5982e583c2c7375f94c107340; PSINO=1; H_PS_PSSID=1426_12897_21103_18560_17001_20698_20927; Hm_lvt_7a3960b6f067eb0085b7f96ff5e660b0=1519646206,1519716112,1519716809,1519719595; Hm_lpvt_7a3960b6f067eb0085b7f96ff5e660b0=1519719595; PANPSC=18290615910929621038%3AkFAYaW5%2Fpj6zizBeZP6vUO2OCisiiAoOHn1ompVCKryY18ddf7emeSQaInMCgWjNXvSRyJUm4ilEb14NLmnOnR5Ym3wTFmoInULx19bZb9CQBDZfhkpW%2FGVWcHP9mn3MPjCB1D%2FVxYyaB5R8hpvpEDWPC7NKcJhVB7o5UgPoMUGwcc33C7HckA%3D%3D; cflag=13%3A3";
        cookie = "BDUSS=XlOT29BM1ZUc2FxWDdUWC12NGV4dHo5MGx1Q3l3a2pKMX5mOGZib2U4RWRFcnBhQVFBQUFBJCQAAAAAAAAAAAEAAACu-7lRbmV2ZXJzdG9wMTEyNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB2FklodhZJae; STOKEN=167a17a10746c1b7f00e9bcb64d6f587fdd175e5982e583c2c7375f94c107340";
        RequestBean requestBean = new RequestBean();
        requestBean.setUrl(url);
        requestBean.setCookie(cookie);


        String content = DiskUtils.getJson(requestBean,"/学习视频",200);
        List<ElementBean> list = DiskUtils.elementsListJsonToObj(content);
        for (ElementBean elementBean : list) {
            System.out.println(elementBean.getServerFilename());
        }
*/
//        String url = "https://pan.baidu.com/api/create?a=commit&channel=chunlei&web=1&app_id=250528&bdstoken=a107e755769b100902519bb9ae266cee&logid=MTUxOTczMDI3NDMzNTAuOTQzNDMxOTc1NTQwNDI1NQ==&clienttype=0";
        //String cookie = "PANWEB=1; bdshare_firstime=1496644750149; FP_UID=4a1833ca6f29714baf079a9790f28c7c; secu=1; PSTM=1497491654; BIDUPSID=CBEEA88423F134632B3067752AFC4183; BAIDUID=8E46A4EB4758D69DABBC6092ECD25484:FG=1; __cfduid=dbd5170cf36256a51d3d49ecaf23d38251500350738; BDCLND=EogXDLjK02advvE%2FvQiEYz1TIZ%2BNVDYlnK63XXLaI1Y%3D; SCRC=d47c39e1d7eaee07396777c74af230e9; BDUSS=XlOT29BM1ZUc2FxWDdUWC12NGV4dHo5MGx1Q3l3a2pKMX5mOGZib2U4RWRFcnBhQVFBQUFBJCQAAAAAAAAAAAEAAACu-7lRbmV2ZXJzdG9wMTEyNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB2FklodhZJae; STOKEN=167a17a10746c1b7f00e9bcb64d6f587fdd175e5982e583c2c7375f94c107340; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; H_PS_PSSID=1426_12897_21103_18560_17001_20698_20927; PSINO=3; cflag=15%3A3; BDRCVFR[feWj1Vr5u3D]=mk3SLVN4HKm; Hm_lvt_7a3960b6f067eb0085b7f96ff5e660b0=1519716809,1519719595,1519730266,1519734388; Hm_lpvt_7a3960b6f067eb0085b7f96ff5e660b0=1519734388; PANPSC=4655294662543676486%3AkFAYaW5%2Fpj6zizBeZP6vUO2OCisiiAoOHn1ompVCKryY18ddf7emeSQaInMCgWjNzWa01xvNJih5hG1Hh4rs3B5Ym3wTFmoInULx19bZb9CQBDZfhkpW%2FGVWcHP9mn3MPjCB1D%2FVxYyaB5R8hpvpEDWPC7NKcJhVB7o5UgPoMUGwcc33C7HckA%3D%3D";

//        System.out.println(body);
//
//        ElementBean folder = JsoupUtils.createFolder(url, cookie, "/2017.10/C最帅哈哈哈");
//        System.out.println(folder.toString());


//        String url = "https://pan.baidu.com/api/quota?checkexpire=1&checkfree=1&channel=chunlei&web=1&app_id=250528&bdstoken=a107e755769b100902519bb9ae266cee&logid=MTUxOTczNTYzODIzNjAuNjgxMDYyNTg4NjYxNTYwMg==&clienttype=0";
//        cookie = "PANWEB=1; bdshare_firstime=1496644750149; FP_UID=4a1833ca6f29714baf079a9790f28c7c; secu=1; PSTM=1497491654; BIDUPSID=CBEEA88423F134632B3067752AFC4183; BAIDUID=8E46A4EB4758D69DABBC6092ECD25484:FG=1; __cfduid=dbd5170cf36256a51d3d49ecaf23d38251500350738; BDCLND=EogXDLjK02advvE%2FvQiEYz1TIZ%2BNVDYlnK63XXLaI1Y%3D; SCRC=d47c39e1d7eaee07396777c74af230e9; BDUSS=XlOT29BM1ZUc2FxWDdUWC12NGV4dHo5MGx1Q3l3a2pKMX5mOGZib2U4RWRFcnBhQVFBQUFBJCQAAAAAAAAAAAEAAACu-7lRbmV2ZXJzdG9wMTEyNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB2FklodhZJae; STOKEN=167a17a10746c1b7f00e9bcb64d6f587fdd175e5982e583c2c7375f94c107340; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; cflag=15%3A3; PSINO=3; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; Hm_lvt_7a3960b6f067eb0085b7f96ff5e660b0=1519735530,1519735593,1519735605,1519735622; H_PS_PSSID=1426_12897_21103_18560_17001_20698_20927; Hm_lpvt_7a3960b6f067eb0085b7f96ff5e660b0=1519740727; PANPSC=6291394805575646769%3AkFAYaW5%2Fpj6zizBeZP6vUO2OCisiiAoOHn1ompVCKryY18ddf7emeSQaInMCgWjNR%2Bet%2FzCiwL%2B3b07WSCcZiR5Ym3wTFmoInULx19bZb9CQBDZfhkpW%2FGVWcHP9mn3MPjCB1D%2FVxYyaB5R8hpvpEDWPC7NKcJhVB7o5UgPoMUGwcc33C7HckA%3D%3D";
//        MemoryInfoBean memoryInfo = JsoupUtils.getMemoryInfo(url, cookie);
//

//        String url = "https://pan.baidu.com/share/set?channel=chunlei&clienttype=0&web=1&channel=chunlei&web=1&app_id=250528&bdstoken=a107e755769b100902519bb9ae266cee&logid=MTUxOTc5MTcxNzM2NTAuNDI0MDQyODY5MTI5MjcwOA==&clienttype=0";
//
         /* RequestBean requestBean = new RequestBean();
          requestBean.setUrl("https://pan.baidu.com/share/set?channel=chunlei&clienttype=0&web=1&channel=chunlei&web=1&app_id=250528&bdstoken=a107e755769b100902519bb9ae266cee&logid=MTUxOTc5MTcxNzM2NTAuNDI0MDQyODY5MTI5MjcwOA==&clienttype=0");
          requestBean.setCookie("BDUSS=XlOT29BM1ZUc2FxWDdUWC12NGV4dHo5MGx1Q3l3a2pKMX5mOGZib2U4RWRFcnBhQVFBQUFBJCQAAAAAAAAAAAEAAACu-7lRbmV2ZXJzdG9wMTEyNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB2FklodhZJae; STOKEN=167a17a10746c1b7f00e9bcb64d6f587fdd175e5982e583c2c7375f94c107340");
          Map<String,String> map = new HashMap<String,String>();
          map.put("fid_list","[182969147331501]");
           map.put("pwd", "aaaa");
            map.put("period", "0");
         map.put("channel_list", "[]");
             map.put("schannel", "4");
           requestBean.setData(map);

        ShareInfoBean shareInfoBean = DiskUtils.getShareInfoBean(requestBean);*/





      /*  File file = new File("F://aaa.txt");
        String name = file.getName();
        long size = file.length();
        String time = new Date().getTime() / 1000 + "";

        //文件上传
        RequestBean requestBean = new RequestBean();
        //requestBean.setUrl("https://pan.baidu.com/api/precreate?channel=chunlei&web=1&app_id=250528&bdstoken=ab56a4771723d6d351aa8b94ca98da28&logid=MTUxOTg3MTIyNDkyNjAuODE5MDgxOTUxODUwODE2Mw==&clienttype=0");
        requestBean.setUrl("http://pan.baidu.com/api/precreate?clienttype=8&channel=00000000000000000000000000000000&version=6.0.1.1&devuid=BDIMXV2-O_F55FFC0A31964CFFBCD56671637BDD5A-C_0-D_32533752584e4830303637343530204c20202020-M_8CDCD46E275D-V_3A80AA7F&rand=8f1be5dcd8ac9464e5f7f43bc3b352ef58e216c7&vip=0&logid=JwAxADUAMQA5ADkANwAwADAANQA0ACwAMQA3ADIALgAxADYALgAyADAAMQAuADEANgAxACwA%0AOAA2ADAAMAAsADEAOAAxADYANgAnAA==&dp-logid=1593804119397504597 ");
        //预创建
        //文件<4M,使用默认的block_list
        requestBean.setCookie("PANPSC=7388070942051638478%3Acvzr9Jxhf5CztnAVbNbdaiOAoXNFwReX%2F%2BcmPtspdDnxTJ3v1z1m%2BjdABFo1yisFP6IhUf59K9t%2BSJWX9%2F9F%2FCC9yOinRwwiKg6bXhEDmDblx9uR5zc7VuiJBQgdZgChTWjERjvPpjKZZzTjcgkmUgTzpkBKRW9%2BC8CAS9ZCtAkefWialUIqvK3gXys9VMIR; BAIDUID=20FACEF099D7493A5336E2303959D52F:FG=1; STOKEN=84012b05c118184ef5fcc866cc4824ddf5aa8955277ccd577a995e7daa4d42db; BDUSS=xqMHc0bGZvby04MjBnMmt0Ty1nWkxrRzRWaGhDYXA2ZjZ6WjZHd3NiRnVhbUJhQVFBQUFBJCQAAAAAAAAAAAEAAACu-7lRbmV2ZXJzdG9wMTEyNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAG7dOFpu3ThaRU");
        Map map = new HashMap();
        map.put("path", "/test/"+name);
        map.put("size",size+"");
        map.put("autoinit", "1");
        map.put("block_list","[\"37350f2eff14380e85c592cbea25915\"]");//默认值837350f2eff14380e85c592cbea25915
        map.put("local_mtime",time);
        map.put("local_ctime",time);
        map.put("method", "post");
        map.put("isdir", "0");
        map.put("time",time);
        requestBean.setData(map);
        //----------获取上传uploadid
        Connection con = JsoupUtils.getConnection(requestBean)
                .method(Connection.Method.POST)
                .header("User-Agent","netdisk;6.0.1.1;PC;PC-Windows;6.1.7601;WindowsBaiduYunGuanJia")
                .header("Content-Type","application/x-www-form-urlencoded")
                .header("Host","d.pcs.baidu.com");


        String body = con.execute().body();
        String uploadid = com.alibaba.fastjson.JSONObject.parseObject(body).getString("uploadid");
        System.out.println(body+"=============="+uploadid);
        //正式上传
        String url = "http://c3.pcs.baidu.com/rest/2.0/pcs/superfile2?app_id=250528&method=upload&path=%2Ftest%2F%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6%E5%A4%B9%2Erar&uploadid=P1%2DMTAuNTIuMjEuMTI6MTUxOTk2MDM5MjoxNTkzNzkzOTg3NTU0Nzg2NjIx&partseq=2&partoffset=8388608&clienttype=8&channel=00000000000000000000000000000000&version=6.0.1.1&devuid=BDIMXV2%2DO%5FF55FFC0A31964CFFBCD56671637BDD5A%2DC%5F0%2DD%5F32533752584e4830303637343530204c20202020%2DM%5F8CDCD46E275D%2DV%5F3A80AA7F&rand=6e144bb0b061183ccb8f97f698f0b044244c3a6d&time=1519961639&vip=0&upload_server=c3.pcs.baidu.com&client_ip=220.248.58.114&logid=JwAxADUAMQA5ADkANgAwADMAOQAyACwAMQA3ADIALgAxADYALgAyADAAMQAuADEANgAxACwA%0AOAA2ADAAMAAsADEAMQAxADkAMgAnAA%3D%3D";

        String fileRquestParam = "file";
        Map<String, String> dataMap = new HashMap<String, String>();
        dataMap.put("path", "/test/"+name);
        dataMap.put("uploadid", uploadid);
        Connection.Response response = doPostFileRequest(url, dataMap, file, fileRquestParam);
        String result = response.body();
        //获取到上传文件的md5
        String md5 = com.alibaba.fastjson.JSONObject.parseObject(result).getString("md5");
        System.out.println(response.body());
        System.out.println(md5+"========"+time);

        //创建上传的文件
        String value = "http://pan.baidu.com/api/create?a=commit&clienttype=8&channel=00000000000000000000000000000000&version=6.0.1.1&devuid=BDIMXV2-O_F55FFC0A31964CFFBCD56671637BDD5A-C_0-D_32533752584e4830303637343530204c20202020-M_8CDCD46E275D-V_3A80AA7F&rand=ded05117df38a05752b084aa97b9e63162187c6f&vip=0&logid=JwAxADUAMQA5ADkANwAwADAANgA1ACwAMQA3ADIALgAxADYALgAyADAAMQAuADEANgAxACwAOAA2ADAAMAAsADEANwAwADEANAAnAA==&dp-logid=1593804131344782911&time="+time;
        Map map1 = new HashMap();
        map1.put("block_list", "[\""+md5+"\"]");
        map1.put("isdir", "0");
        map1.put("method","post");
        map1.put("mode","1" );
        map1.put("path", dataMap.get("path"));
        map1.put("rtype", "2");
        map1.put("sequence","1" );
        map1.put("size",size);
        map1.put("uploadid", uploadid);
        map1.put("local_ctime", time);
        map1.put("local_mtime", time);
        RequestBean requestBean1 = new RequestBean();
        requestBean1.setUrl(url);
        requestBean.setData(map1);
        requestBean.setCookie("PANPSC=7388070942051638478%3Acvzr9Jxhf5CztnAVbNbdaiOAoXNFwReX%2F%2BcmPtspdDnxTJ3v1z1m%2BjdABFo1yisFP6IhUf59K9t%2BSJWX9%2F9F%2FCC9yOinRwwiKg6bXhEDmDblx9uR5zc7VuiJBQgdZgChTWjERjvPpjKZZzTjcgkmUgTzpkBKRW9%2BC8CAS9ZCtAkefWialUIqvK3gXys9VMIR; BAIDUID=20FACEF099D7493A5336E2303959D52F:FG=1; STOKEN=84012b05c118184ef5fcc866cc4824ddf5aa8955277ccd577a995e7daa4d42db; BDUSS=xqMHc0bGZvby04MjBnMmt0Ty1nWkxrRzRWaGhDYXA2ZjZ6WjZHd3NiRnVhbUJhQVFBQUFBJCQAAAAAAAAAAAEAAACu-7lRbmV2ZXJzdG9wMTEyNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAG7dOFpu3ThaRU");
        Connection cc = JsoupUtils.getConnection(requestBean)
                .method(Connection.Method.POST)
                .header("Content-Type","application/x-www-form-urlencoded")
                .header("User-Agent","netdisk;6.0.1.1;PC;PC-Windows;6.1.7601;WindowsBaiduYunGuanJia");
        String body1 = cc.execute().body();
        System.out.println(body1+"==================");


        System.out.println(size+"==========");*/

    }

    /**
     * @param url              请求的Url
     * @param paramMap         参数
     * @param file             文件
     * @param fileRequestParam form表单对应的文件name属性名
     * @return
     * @throws Exception
     */
    public static Connection.Response doPostFileRequest(String url, Map<String, String> paramMap, File file, String fileRequestParam) throws Exception {
        if (StringUtils.isBlank(url)) {
            throw new Exception("The request URL is blank.");
        }

        Connection connection = Jsoup.connect(url);
        connection.method(Connection.Method.POST);
        connection.timeout(120000);
        connection.header("Content-Type", "multipart/form-data");
        connection.ignoreHttpErrors(true);
        connection.ignoreContentType(true);
        connection.header("Cookie", "BDUSS=XlOT29BM1ZUc2FxWDdUWC12NGV4dHo5MGx1Q3l3a2pKMX5mOGZib2U4RWRFcnBhQVFBQUFBJCQAAAAAAAAAAAEAAACu-7lRbmV2ZXJzdG9wMTEyNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB2FklodhZJae; STOKEN=167a17a10746c1b7f00e9bcb64d6f587fdd175e5982e583c2c7375f94c107340");
        if (paramMap != null && !paramMap.isEmpty()) {
            connection.data(paramMap);
        }
        try {
            FileInputStream fis = new FileInputStream(file);
            connection.data(fileRequestParam, file.getName(), fis);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            Connection.Response response = connection.execute();
            if (response.statusCode() != HttpStatus.SC_OK) {
                throw new Exception("http请求响应码:" + response.statusCode() + "");
            }
            return response;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }




}
